package com.jd.autobean;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class GenerateBeans {
	
	public String table;
	
	public Map<String,String> filedMap;
	
	private String[] fileds;
	
	public static void main(String[] args) {
		
		GenerateBeans gbean = new GenerateBeans();
		gbean.filedMap.put("id", "id");
		gbean.filedMap.put("evidence_source", "evidenceSource");
		gbean.filedMap.put("merchant_no", "merchantNo");
		gbean.filedMap.put("merchant_name", "merchantName");
		gbean.filedMap.put("merchant_trade_no", "merchantTradeNo");
		gbean.filedMap.put("bank_order_no", "bankOrderNo");
		gbean.filedMap.put("pay_tool", "payTool");
		gbean.filedMap.put("trade_bank", "tradeBank");
		gbean.filedMap.put("trade_time", "tradeTime");
		gbean.filedMap.put("trade_count", "tradeCount");
		gbean.filedMap.put("trade_amount", "tradeAmount");
		gbean.filedMap.put("create_person", "createPerson");
		gbean.filedMap.put("update_person", "updatePerson");
		gbean.filedMap.put("created_time", "createdTime");
		gbean.filedMap.put("modified_time", "modifiedTime");
		
		
		System.out.println(gbean.generateInsert());
	}
	
	
	
	public GenerateBeans() {
		super();
		filedMap = new HashMap<String, String>();
	}



	public String generateInsert()
	{
		StringBuffer sb = new StringBuffer();
		sb.append("<insert id=\"save\" parameterType=\"\" useGeneratedKeys=\"true\" keyProperty=\"id\">\")\n");
		sb.append("insert into "+table+"\n");
		sb.append(" <trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\" >\n");
		for(Entry<String, String> entry: filedMap.entrySet())
		{
			sb.append("<if test=\"" +entry.getKey() +"!= null\" > "+entry.getValue()+",</if>\n");
		}
		sb.append("</trim>\n");
		
		sb.append("<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\" >\n");
		for(String key: filedMap.keySet())
		{
			sb.append("<if test=\"" +key +"!= null\" > #{"+  key  +", jdbcType=\"VARCHAR\"},</if>\n");
		}
		sb.append("</trim>\n");
		return sb.toString();
	}
}
